package com.example.demo.controller;

import com.example.demo.pojo.Users;
import com.example.demo.service.UserService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName UserController
 * @Description TODO
 * @Author zhangshuai
 * @Date 2019/6/30 15:33
 * @Version 1.0
 **/
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/helloUser/{id}")
    public String selectUser(@PathVariable Long id) {
        Users users = userService.selectUser(id);
        return users.getUserName();
    }

    @RequestMapping("/helper/{id}")
    public Map<String, Object> selectUsers(@PathVariable Long id) {

        //Map<String, Object> map = new HashMap<>();

        Map<String, Object> map = userService.selectUser();
        // System.out.println(usersList.toString());  //输出的是page对象

      /*  for (int i = 0; i < usersList.size(); i++) {
            System.out.println(usersList.get(i)); //获取分页的结果
        }*/
        //map.put("usersList", usersList);
        //map.put("page", usersList.toString());
        return map;
    }

    @RequestMapping("/saveUser")
    public void saveUser() {
        userService.saves();
    }


}
